angular.module('withdraw-cash',[])

.controller 'withdrawCashCtrl', ($scope,$http,$state,$ionicHistory,$ionicScrollDelegate,userData) ->
    loadData=()->
        $http.get '/accounts',params:{action:'getallcash',userid:userData.getToken()}
        .success (resp) ->
            if resp.status == '0'
                $scope.balance=resp.allcash
        $http.get '/accounts',params:{action:'cashlist',userid:userData.getToken(),page:1,pagesize:$scope.pagesize}
        .success (resp) ->
            if resp.status == '0'
                console.log resp
                $scope.allpage=Number(resp.allpage) if Number(resp.allpage)>0
                $scope.cashlist=resp.cashlist
    $scope.$on '$ionicView.enter',->
        $scope.page=1
        $scope.allpage=1
        $scope.cashlist=[]
        loadData()
    _.extend $scope,
        pagesize:8
        goBack: ->
            $ionicHistory.goBack()
        goCash:->
            $state.go 'tab.withdraw-cash-form'
        refreshData:()->
            $scope.tradelist=[]
            console.log $scope.page
            $http.get '/accounts',params:{action:'cashlist',userid:userData.getToken(),page:$scope.page,pagesize:$scope.pagesize}
            .success (resp) ->
                if resp.status == '0'
                    console.log resp
                    $scope.cashlist=resp.cashlist
#                    $scope.tips=resp.tips
        nextPage:->
            if $scope.page>=$scope.allpage
                return
            $scope.page=$scope.page+1
            $ionicScrollDelegate.$getByHandle().scrollTop()
            $scope.refreshData()
        prePage:->
            if $scope.page<=1
                return
            $scope.page=$scope.page-1
            $ionicScrollDelegate.$getByHandle().scrollTop()
            $scope.refreshData()